home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / irit / irit.c < prev    next >
C/C++ Source or Header  |  1995-12-30  |  30KB  |  720 lines

  1. /*****************************************************************************
  2. *   Main module of "Irit" - the 3d (not only polygonal) solid modeller.      *
  3. ******************************************************************************
  4. * Usage:                                     *
  5. *   Irit [-t] [-z]                                 *
  6. *                                         *
  7. * Written by:  Gershon Elber                Ver 3.0, Apr. 1990   *
  8. *****************************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <signal.h>
  12. #include <string.h>
  13. #include "program.h"
  14. #include "config.h"
  15. #include "ctrl-brk.h"
  16. #include "dosintr.h"
  17. #include "inptprsg.h"
  18. #include "iritprsr.h"
  19. #include "irit_soc.h"
  20. #include "objects.h"
  21. #include "windows.h"
  22. #include "iritgrap.h"
  23. #include "bool_lib.h"
  24. #include "trim_lib.h"
  25. #include "triv_lib.h"
  26. #include "symb_lib.h"
  27. #ifdef __WINNT__
  28. #include <direct.h>
  29. #endif /* __WINNT__ */
  30. #ifdef DJGCC
  31. #include "intr_lib.h"
  32. #include "intr_gr.h"
  33. #endif /* DJGCC */
  34.  
  35. #ifdef NO_CONCAT_STR
  36. static char *VersionStr = "Irit        Version 5.0, Gershon Elber,\n\
  37.     (C) Copyright 1989/90-95 Gershon Elber, Non commercial use only.";
  38. #else
  39. static char *VersionStr = "Irit            " VERSION
  40.     ",    Gershon Elber,    " __DATE__ ",   " __TIME__ "\n"
  41.     COPYRIGHT ", Non commercial use only.";
  42. #endif /* NO_CONCAT_STR */
  43.  
  44. static char *CtrlStr = "Irit [-t] [-z] [file.irt]";
  45.  
  46. char *GlblHelpFileName = "irit.hlp";
  47.  
  48. static char
  49.      *GlblPrgmHeader = "                Irit - the not only polygonal solid modeller";
  50. static char
  51.      *GlblCopyRight  =
  52. #ifdef DJGCC
  53.      COPYRIGHT ",  DJGCC " VERSION ",   " __DATE__;
  54. #else
  55. #ifdef OS2GCC
  56.      COPYRIGHT ",  OS2   " VERSION ",   " __DATE__;
  57. #else
  58. #ifdef AMIGA
  59.      COPYRIGHT ", Amiga  " VERSION ",   " __DATE__;
  60. #else
  61. #ifdef NO_CONCAT_STR
  62.      "(C) Copyright 1989/90-95 Gershon Elber,  Unix  Version 5.0";
  63. #else
  64.      COPYRIGHT ",  Unix  " VERSION;
  65. #endif /* NO_CONCAT_STR */
  66. #endif /* AMIGA */
  67. #endif /* OS2GCC */
  68. #endif /* DJGCC */
  69. static char
  70.     *GlblAuthorName = "                         Written by Gershon Elber";
  71.  
  72. IPObjectStruct
  73.     *GlblObjList = NULL;           /* All objects defined on system. */
  74.  
  75. char GlblCrntWorkingDir[LINE_LEN];     /* Save start CWD to recover on exit. */
  76.  
  77. FILE
  78.     *GlblLogFile = NULL;
  79.  
  80. jmp_buf GlblLongJumpBuffer;                  /* Used in error recovery. */
  81.  
  82. int
  83. #ifdef DJGCC                       /* Defaults for intr_lib. */
  84.     GlblWindowFrameWidth = 8,
  85.     GlblViewFrameColor   = INTR_COLOR_RED,
  86.     GlblViewBackColor    = INTR_COLOR_BLACK,
  87.     GlblTransFrameColor  = INTR_COLOR_GREEN,
  88.     GlblTransBackColor   = INTR_COLOR_BLACK,
  89.     GlblStatusFrameColor = INTR_COLOR_MAGENTA,
  90.     GlblStatusBackColor  = INTR_COLOR_BLACK,
  91.     GlblInputFrameColor  = INTR_COLOR_YELLOW,
  92.     GlblInputBackColor   = INTR_COLOR_BLACK,
  93.     GlblDrawHeader       = FALSE,
  94.     GlblSmoothTextScroll = TRUE,
  95.     GlblIntrSaveMethod   = INTR_SAVE_DISK,
  96.     GlblMouseSensitivity = 10,       /* Sensitivity control of mouse device. */
  97.     GlblJoystickExists   = FALSE,
  98. #endif /* DJGCC */
  99.     GlblDisplayDeviceInput = -1,
  100.     GlblDisplayDeviceOutput = -1,
  101.     GlblInterpProd     = TRUE,
  102.     GlblLoadColor        = DEFAULT_LOAD_COLOR,
  103.     GlblPrimColor        = DEFAULT_PRIM_COLOR,
  104.     GlblDoGraphics       = TRUE,/* Control if running in graphics/text mode. */
  105.     GlblFatalError       = FALSE, /* True if disaster in system - must quit! */
  106.     GlblPrintLogFile     = FALSE,    /* If TRUE everything goes to log file. */
  107.     GlblPointLenAux      = IG_POINT_DEFAULT_LENGTH;
  108.  
  109. RealType
  110.     GlblPointLen = 0.02;               /* Scaler for point if drawn. */
  111.  
  112. char
  113. #ifdef DJGCC                       /* Defaults for intr_lib. */
  114.     *GlblViewWndwPos   = "0.02, 0.02, 0.72, 0.66",
  115.     *GlblTransWndwPos  = "0.75, 0.02, 0.98, 0.66",
  116.     *GlblStatusWndwPos = "0.75, 0.02, 0.98, 0.66",
  117.     *GlblInputWndwPos  = "0.04, 0.7,  0.98, 0.98",
  118.     *GlblIntrSaveDisk  = "c:\\",
  119. #endif /* DJGCC */
  120.     *GlblStartFileName = "",
  121.     *GlblLogFileName = "",
  122. #ifdef DOUBLE
  123.     *GlblFloatFormat = "%-8.6lg";
  124. #else
  125.     *GlblFloatFormat = "%-8.6g";
  126. #endif /* DOUBLE */
  127.  
  128. static ConfigStruct SetUp[] =
  129. {
  130. #ifdef DJGCC
  131.   { "Joystick",        "",   (VoidPtr) &GlblJoystickExists, SU_BOOLEAN_TYPE },
  132.   { "MouseSensitivity",    "",   (VoidPtr) &GlblMouseSensitivity,SU_INTEGER_TYPE },
  133.   { "WndwWidth",    "",   (VoidPtr) &GlblWindowFrameWidth,SU_INTEGER_TYPE },
  134.   { "WndwHeader",    "",   (VoidPtr) &GlblDrawHeader,     SU_BOOLEAN_TYPE },
  135.   { "WndwSmthTxtScrl",    "",   (VoidPtr) &GlblSmoothTextScroll,SU_BOOLEAN_TYPE },
  136.   { "WndwViewClr",    "",   (VoidPtr) &GlblViewFrameColor, SU_INTEGER_TYPE },
  137.   { "WndwTransClr",    "",   (VoidPtr) &GlblTransFrameColor,SU_INTEGER_TYPE },
  138.   { "WndwInputClr",    "",   (VoidPtr) &GlblInputFrameColor,SU_INTEGER_TYPE },
  139.   { "WndwViewPos",    "",   (VoidPtr) &GlblViewWndwPos,    SU_STRING_TYPE },
  140.   { "WndwTransPos",    "",   (VoidPtr) &GlblStatusWndwPos,  SU_STRING_TYPE },
  141.   { "WndwInputPos",    "",   (VoidPtr) &GlblInputWndwPos,   SU_STRING_TYPE },
  142.   { "WndwBackSave",    "",   (VoidPtr) &GlblIntrSaveMethod, SU_INTEGER_TYPE },
  143.   { "WndwBackSavePath",    "",   (VoidPtr) &GlblIntrSaveDisk,   SU_STRING_TYPE },
  144. #endif /* DJGCC */
  145.   { "DoGraphics",    "-t", (VoidPtr) &GlblDoGraphics,     SU_BOOLEAN_TYPE },
  146.   { "InterpProd",    "",   (VoidPtr) &GlblInterpProd,     SU_BOOLEAN_TYPE },
  147.   { "PointLength",    "",   (VoidPtr) &GlblPointLenAux,    SU_INTEGER_TYPE },
  148.   { "LoadColor",    "",   (VoidPtr) &GlblLoadColor,         SU_INTEGER_TYPE },
  149.   { "PrimColor",    "",   (VoidPtr) &GlblPrimColor,         SU_INTEGER_TYPE },
  150.   { "StartFile",    "",   (VoidPtr) &GlblStartFileName,  SU_STRING_TYPE },
  151.   { "LogFile",        "",   (VoidPtr) &GlblLogFileName,    SU_STRING_TYPE },
  152.   { "FloatFrmt",    "",   (VoidPtr) &GlblFloatFormat,    SU_STRING_TYPE },
  153. };
  154. #define NUM_SET_UP    (sizeof(SetUp) / sizeof(ConfigStruct))
  155.  
  156. static void Interact(void);
  157. static void PrintInptPrsrError(void);
  158.  
  159. /*****************************************************************************
  160. * DESCRIPTION:                                                               M
  161. * Main module of IRIT - Read command line and do what is needed...         M
  162. *                                                                            *
  163. * PARAMETERS:                                                                M
  164. *   argc, argv:  Command line.                                               M
  165. *                                                                            *
  166. * RETURN VALUE:                                                              M
  167. *   void                                                                     M
  168. *                                                                            *
  169. * KEYWORDS:                                                                  M
  170. *   main                                                                     M
  171. *****************************************************************************/
  172. void main(int argc, char **argv)
  173. {
  174.     char *FullPathStartFileName;
  175.  
  176.     IritCPUTime(TRUE);                     /* Reset the clock. */
  177.  
  178.     Config("irit", SetUp, NUM_SET_UP);       /* Read config. file if exists. */
  179.  
  180.     while (argc >= 2) {
  181.         if (strncmp(argv[1], "-z", 2) == 0) {
  182.         fprintf(stderr, "\n%s\n\nUsage: %s\n", VersionStr, CtrlStr);
  183.         ConfigPrint(SetUp, NUM_SET_UP);
  184.         exit(0);
  185.         }
  186.     else if (strncmp(argv[1], "-t", 2) == 0) {
  187.         GlblDoGraphics = FALSE;
  188.     }
  189.     else {
  190.         break;
  191.     }
  192.         argv++;
  193.     argc--;
  194.     }
  195.  
  196.     getcwd(GlblCrntWorkingDir, LINE_LEN - 1);
  197.  
  198.     SetUpCtrlBrk();         /* Set up control break trap routine (int 1bh). */
  199.     signal(SIGFPE, DefaultFPEHandler);     /* Will trap floating point errors. */
  200.  
  201.     BspMultInterpFlag(GlblInterpProd);
  202.     IritPrsrSetFloatFormat(GlblFloatFormat);
  203.     IritPrsrSetFlattenObjects(FALSE);
  204.     IritPrsrSetPolyListCirc(TRUE);
  205.  
  206.     /* Print some copyright messages: */
  207.     WndwInputWindowPutStr(GlblPrgmHeader);
  208.     WndwInputWindowPutStr(GlblCopyRight);
  209.     WndwInputWindowPutStr(GlblAuthorName);
  210.  
  211.     SetUpPredefObjects();          /* Prepare the predefined objects. */
  212.  
  213.     /* Execute the file specified in the command line if was one: */
  214.     if (argc == 2)
  215.     FileInclude(argv[1]);
  216.  
  217.     /* Execute the start up file first by inserting it to the include stack. */
  218.     if ((int) strlen(GlblStartFileName) > 0 &&
  219.     (FullPathStartFileName = searchpath(GlblStartFileName)) != NULL)
  220.     FileInclude(FullPathStartFileName);
  221.  
  222.     Interact();                      /* Go and do some real work... */
  223.  
  224.     IritExit(0);
  225. }
  226.  
  227. /*****************************************************************************
  228. * DESCRIPTION:                                                               *
  229. * Interact - the main read/eval/print routine. This routine reads data from  *
  230. * standart input and execute it "forever" (using Input Parser).             *
  231. *   Note exit from this program is controled by input parser itself.         *
  232. *                                                                            *
  233. * PARAMETERS:                                                                *
  234. *   None                                                                     *
  235. *                                                                            *
  236. * RETURN VALUE:                                                              *
  237. *   void                                                                     *
  238. *****************************************************************************/
  239. static void Interact(void)
  240. {
  241.     /* setjmp return 0 on first install time. Will return 1 if error is      */
  242.     /* recoverable, 2 if cannt continue - must quit the program now.         */
  243.     switch (setjmp(GlblLongJumpBuffer)) {         /* Used in error recovery. */
  244.     case 0:
  245.     case 1:
  246.         while (TRUE) {
  247.         if (!InputParser())         /* Print the error message. */
  248.             PrintInptPrsrError();
  249.         }
  250.     case 2:
  251.         WndwInputWindowPutStr("Press return to die...");
  252.         getchar();
  253.         break;
  254.     }
  255. }
  256.  
  257. /*****************************************************************************
  258. * DESCRIPTION:                                                               M
  259. * Modifies the state of the IRIT solid modeller.                 M
  260. *                                                                            *
  261. * PARAMETERS:                                                                M
  262. *   Name:      Name of state variable.                                       M
  263. *   Data:      New value of state variable.                                  M
  264. *                                                                            *
  265. * RETURN VALUE:                                                              M
  266. *   void                                                                     M
  267. *                                                                            *
  268. * KEYWORDS:                                                                  M
  269. *   SetIritState                                                             M
  270. *****************************************************************************/
  271. void SetIritState(char *Name, IPObjectStruct *Data)
  272. {
  273.     if (stricmp(Name, "InterpProd") == 0) {
  274.     if (IP_IS_NUM_OBJ(Data))
  275.         BspMultInterpFlag(REAL_TO_INT(Data -> U.R));
  276.     else
  277.         WndwInputWindowPutStr("Numeric state value expected");
  278.     }
  279.     else if (stricmp(Name, "DebugFunc") == 0) {
  280.     if (IP_IS_NUM_OBJ(Data))
  281.         InptPrsrDebugFuncLevel(REAL_TO_INT(Data -> U.R));
  282.     else
  283.         WndwInputWindowPutStr("Numeric state value expected");
  284.     }
  285.     else if (stricmp(Name, "EchoSource") == 0) {
  286.     if (IP_IS_NUM_OBJ(Data))
  287.         InptPrsrEchoSource(REAL_TO_INT(Data -> U.R));
  288.     else
  289.         WndwInputWindowPutStr("Numeric state value expected");
  290.     }
  291.     else if (stricmp(Name, "FloatFrmt") == 0) {
  292.     if (IP_IS_STR_OBJ(Data)) {
  293.         strcpy(GlblFloatFormat, Data -> U.Str);
  294.         IritPrsrSetFloatFormat(GlblFloatFormat);
  295.     }
  296.     else
  297.         WndwInputWindowPutStr("String state value expected");
  298.     }
  299.     else if (stricmp(Name, "InterCrv") == 0) {
  300.     if (IP_IS_NUM_OBJ(Data))
  301.         BoolSetOutputInterCurve(REAL_TO_INT(Data -> U.R));
  302.     else
  303.         WndwInputWindowPutStr("Numeric state value expected");
  304.     }
  305.     else if (stricmp(Name, "Coplanar") == 0) {
  306.     if (IP_IS_NUM_OBJ(Data))
  307.         BoolSetHandleCoplanarPoly(REAL_TO_INT(Data -> U.R));
  308.     else
  309.         WndwInputWindowPutStr("Numeric state value expected");
  310.     }
  311.     else if (stricmp(Name, "PolySort") == 0) {
  312.     if (IP_IS_NUM_OBJ(Data))
  313.         BoolSetPolySortAxis(REAL_TO_INT(Data -> U.R));
  314.     else
  315.         WndwInputWindowPutStr("Numeric state value expected");
  316.     }
  317.     else if (stricmp(Name, "DumpLevel") == 0) {
  318.     if (IP_IS_NUM_OBJ(Data))
  319.         SetDumpLevel(REAL_TO_INT(Data -> U.R));
  320.     else
  321.         WndwInputWindowPutStr("Numeric state value expected");
  322.     }
  323.     else if (stricmp(Name, "TrimCrvs") == 0) {
  324.     if (IP_IS_NUM_OBJ(Data)) {
  325.         TrimSetEuclidComposedFromUV(Data -> U.R <= 0);
  326.         TrimSetTrimCrvLinearApprox((int) (fabs(Data -> U.R)), FALSE);
  327.     }
  328.     else
  329.         WndwInputWindowPutStr("Numeric state value expected");
  330.     }
  331. }
  332.  
  333. /*****************************************************************************
  334. * DESCRIPTION:                                                               *
  335. * Routine to query (and print) the errors found by InputParser.             *
  336. *                                                                            *
  337. * PARAMETERS:                                                                *
  338. *   None                                                                     *
  339. *                                                                            *
  340. * RETURN VALUE:                                                              *
  341. *   void                                                                     *
  342. *****************************************************************************/
  343. static void PrintInptPrsrError(void)
  344. {
  345.     InptPrsrEvalErrType ErrorNum;
  346.     char *ErrorMsg, *p;
  347.     char Line[LINE_LEN_LONG];
  348.  
  349.     if ((ErrorNum = InptPrsrParseError(&ErrorMsg)) != IPE_NO_ERR) {/*Prsr err*/
  350.     sprintf(Line, "Parsing Error: ");
  351.     p = &Line[strlen(Line)];
  352.     switch (ErrorNum) {
  353.         case IP_ERR_WRONG_SYNTAX:
  354.         sprintf(p, "Wrong syntax\n");
  355.         break;
  356.         case IP_ERR_PARAM_EXPECT:
  357.         sprintf(p, "Parameter Expected\n");
  358.         break;
  359.         case IP_ERR_ONE_OPERAND:
  360.         case IP_ERR_TWO_OPERAND:
  361.         sprintf(p, "Wrong # of operands - %s\n", ErrorMsg);
  362.         break;
  363.         case IP_ERR_STACK_OV:
  364.         sprintf(p, "Internal Stack OverFlow at - %s\n", ErrorMsg);
  365.         break;
  366.         case IP_ERR_PARAM_MATCH:
  367.         sprintf(p, "Parenthesis mismatch - %s\n", ErrorMsg);
  368.         break;
  369.         case IP_ERR_UNDEF_TOKEN:
  370.         sprintf(p, "Undefined token - %s\n", ErrorMsg);
  371.         break;
  372.         case IP_ERR_UNDEF_FUNC:
  373.         sprintf(p, "Undefined function - %s\n", ErrorMsg);
  374.         break;
  375.         case IP_ERR_NAME_TOO_LONG:
  376.         sprintf(p, "Object name too long - %s\n", ErrorMsg);
  377.         break;
  378.         case IP_ERR_PARAM_FUNC:
  379.         sprintf(p, "Parameters expected in func %s\n", ErrorMsg);
  380.         break;
  381.         case IP_ERR_NO_PARAM_FUNC:
  382.         sprintf(p, "No Parameters expected in func %s\n", ErrorMsg);
  383.         break;
  384.         case IP_ERR_STR_TOO_LONG:
  385.         sprintf(p, "String too long - %s\n", ErrorMsg);
  386.         break;
  387.         default:
  388.         sprintf(p, "Undefined error %d", ErrorNum);
  389.         break;
  390.     }
  391.     WndwInputWindowPutStr(Line);
  392.     return;
  393.     }
  394.  
  395.     if ((ErrorNum = InptPrsrEvalError(&ErrorMsg)) != IPE_NO_ERR) {/*Eval err.*/
  396.     sprintf(Line, "Eval Error: ");
  397.     p = &Line[strlen(Line)];
  398.     switch (ErrorNum) {
  399.         case IE_ERR_FATAL_ERROR:
  400.         sprintf(p, "Fatal error - %s\n", ErrorMsg);
  401.         break;
  402.         case IE_ERR_DIV_BY_ZERO:
  403.         sprintf(p, "Division by zero - %s\n", ErrorMsg);
  404.         break;
  405.         case IE_ERR_NO_OBJ_METHOD:
  406.         sprintf(p, "No such method for object - %s\n", ErrorMsg);
  407.         break;
  408.         case IE_ERR_TYPE_MISMATCH:
  409.         sprintf(p, "Parameter type mismatch - %s\n",
  410.             ErrorMsg);
  411.         break;
  412.         case IE_ERR_ASSIGN_LEFT_OP:
  413.         sprintf(p, "Lval is not a parameter - %s\n", ErrorMsg);
  414.         break;
  415.         case IE_ERR_MIXED_OBJ:
  416.         sprintf(p, "Mixed types in expression - %s\n", ErrorMsg);
  417.         break;
  418.         case IE_ERR_IP_OBJ_UNDEFINED:
  419.         sprintf(p, "No such object defined - %s\n", ErrorMsg);
  420.         break;
  421.         case IE_ERR_NO_ASSIGNMENT:
  422.         sprintf(p, "Assignment was expected\n");
  423.         break;
  424.         case IE_ERR_FP_ERROR:
  425.         sprintf(p, "Floating Point Error - %s\n", ErrorMsg);
  426.         break;
  427.         case IE_ERR_NUM_PRM_MISMATCH:
  428.         sprintf(p, "Number of func. param. mismatch - %s\n", ErrorMsg);
  429.         break;
  430.         case IE_ERR_MAT_POWER:
  431.         sprintf(p, "Wrong range or not exists, operator - %s\n", ErrorMsg);
  432.         break;
  433.         case IE_ERR_FREE_SIMPLE:
  434.         sprintf(p, "Free only geometric objects - %s\n", ErrorMsg);
  435.         break;
  436.         case IE_ERR_MODIF_ITER_VAR:
  437.         sprintf(p, "Iteration var. type modified or freed - %s\n", ErrorMsg);
  438.         break;
  439.         case IE_ERR_BOOLEAN_ERR:
  440.         sprintf(p, "Geometric Boolean operation error - %s\n", ErrorMsg);
  441.         break;
  442.         case IE_ERR_OUT_OF_RANGE:
  443.         sprintf(p, "Out of range.\n");
  444.         break;
  445.         case IE_ERR_DATA_PRSR_ERROR:
  446.         sprintf(p, "%s", ErrorMsg);
  447.         break;
  448.         case IE_ERR_USER_FUNC_NO_RETVAL:
  449.         sprintf(p, "User defined function \"%s\" has no returned value\n",
  450.             ErrorMsg);
  451.         break;
  452.         case IE_ERR_INCOMPARABLE_TYPES:
  453.         sprintf(p, "Incomparable object types found");
  454.         break;
  455.         case IE_ERR_ONLYEQUALITY_TEST:
  456.         sprintf(p, "Only equality or non equality test is valid for these objects");
  457.         break;
  458.         case IE_ERR_IF_HAS_NO_COND:
  459.         sprintf(p, "Condition of if clause is illegal");
  460.         break;
  461.         case IE_ERR_IP_USERFUNC_DUP_VAR:
  462.         sprintf(p, "Duplicated variable, %s", ErrorMsg);
  463.         break;
  464.         default:
  465.         sprintf(p, "Undefined error %d\n", ErrorNum);
  466.         break;
  467.     }
  468.     WndwInputWindowPutStr(Line);
  469.     return;
  470.     }
  471. }
  472.  
  473. /*****************************************************************************
  474. * DESCRIPTION:                                                               M
  475. * IRIT Exit routine. Error code of zero.                     M
  476. *                                                                            *
  477. * PARAMETERS:                                                                M
  478. *   None                                                                     *
  479. *                                                                            *
  480. * RETURN VALUE:                                                              M
  481. *   void                                                                     M
  482. *                                                                            *
  483. * KEYWORDS:                                                                  M
  484. *   IritExit0                                                                M
  485. *****************************************************************************/
  486. void IritExit0(void)
  487. {
  488.     IritExit(0);
  489. }
  490.  
  491. /*****************************************************************************
  492. * DESCRIPTION:                                                               M
  493. * IRIT Exit routine.                                                M
  494. *                                                                            *
  495. * PARAMETERS:                                                                M
  496. *   ExitCode:   Exit code.                                                   *
  497. *                                                                            *
  498. * RETURN VALUE:                                                              M
  499. *   void                                                                     M
  500. *                                                                            *
  501. * KEYWORDS:                                                                  M
  502. *   IritExit                                                                 M
  503. *****************************************************************************/
  504. void IritExit(int ExitCode)
  505. {
  506.     if (GlblDoGraphics) {
  507.         WndwViewExit();
  508.     }
  509.  
  510.     ClientCloseAll(TRUE);
  511.  
  512.     chdir(GlblCrntWorkingDir);      /* Recover original directory before exit. */
  513.  
  514.     if (GlblPrintLogFile)
  515.     fclose(GlblLogFile);              /* Close log file if was open. */
  516.  
  517.     exit(ExitCode);
  518. }
  519.  
  520. /*****************************************************************************
  521. * DESCRIPTION:                                                               M
  522. * Traps Cagd_lib errors right here. Call back function of cagd_lib.         M
  523. *                                                                            *
  524. * PARAMETERS:                                                                M
  525. *   ErrID:    Error number in cagd_lib library.                              M
  526. *                                                                            *
  527. * RETURN VALUE:                                                              M
  528. *   void                                                                     M
  529. *                                                                            M
  530. * KEYWORDS:                                                                  M
  531. *   CagdFatalError                                                           M
  532. *****************************************************************************/
  533. void CagdFatalError(CagdFatalErrorType ErrID)
  534. {
  535.     char Line[LINE_LEN],
  536.     *ErrorMsg = CagdDescribeError(ErrID);
  537.  
  538.     sprintf(Line, "CAGD_LIB: %s", ErrorMsg);
  539.     WndwInputWindowPutStr(Line);
  540.  
  541.     FlushToEndOfExpr(TRUE);
  542.  
  543.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  544. }
  545.  
  546. /*****************************************************************************
  547. * DESCRIPTION:                                                               M
  548. * Traps Symb_lib errors right here. Call back function of symb_lib.         M
  549. *                                                                            *
  550. * PARAMETERS:                                                                M
  551. *   ErrID:    Error number in symb_lib library.                              M
  552. *                                                                            *
  553. * RETURN VALUE:                                                              M
  554. *   void                                                                     M
  555. *                                                                            M
  556. * KEYWORDS:                                                                  M
  557. *   SymbFatalError                                                           M
  558. *****************************************************************************/
  559. void SymbFatalError(SymbFatalErrorType ErrID)
  560. {
  561.     char Line[LINE_LEN],
  562.     *ErrorMsg = SymbDescribeError(ErrID);
  563.  
  564.     sprintf(Line, "SYMB_LIB: %s", ErrorMsg);
  565.     WndwInputWindowPutStr(Line);
  566.  
  567.     FlushToEndOfExpr(TRUE);
  568.  
  569.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  570. }
  571.  
  572. /*****************************************************************************
  573. * DESCRIPTION:                                                               M
  574. * Traps Trim_lib errors right here. Call back function of trim_lib.         M
  575. *                                                                            *
  576. * PARAMETERS:                                                                M
  577. *   ErrID:    Error number in trim_lib library.                              M
  578. *                                                                            *
  579. * RETURN VALUE:                                                              M
  580. *   void                                                                     M
  581. *                                                                            M
  582. * KEYWORDS:                                                                  M
  583. *   TrimFatalError                                                           M
  584. *****************************************************************************/
  585. void TrimFatalError(TrimFatalErrorType ErrID)
  586. {
  587.     char Line[LINE_LEN],
  588.     *ErrorMsg = TrimDescribeError(ErrID);
  589.  
  590.     sprintf(Line, "TRIM_LIB: %s", ErrorMsg);
  591.     WndwInputWindowPutStr(Line);
  592.  
  593.     FlushToEndOfExpr(TRUE);
  594.  
  595.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  596. }
  597.  
  598. /*****************************************************************************
  599. * DESCRIPTION:                                                               M
  600. * Traps Triv_lib errors right here. Call back function of triv_lib.         M
  601. *                                                                            *
  602. * PARAMETERS:                                                                M
  603. *   ErrID:    Error number in triv_lib library.                              M
  604. *                                                                            *
  605. * RETURN VALUE:                                                              M
  606. *   void                                                                     M
  607. *                                                                            M
  608. * KEYWORDS:                                                                  M
  609. *   TrivFatalError                                                           M
  610. *****************************************************************************/
  611. void TrivFatalError(TrivFatalErrorType ErrID)
  612. {
  613.     char Line[LINE_LEN],
  614.     *ErrorMsg = TrivDescribeError(ErrID);
  615.  
  616.     sprintf(Line, "TRIV_LIB: %s", ErrorMsg);
  617.     WndwInputWindowPutStr(Line);
  618.  
  619.     FlushToEndOfExpr(TRUE);
  620.  
  621.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  622. }
  623.  
  624. /*****************************************************************************
  625. * DESCRIPTION:                                                               M
  626. * Prints IRIT's fatal error message and go back to cursor mode.             M
  627. *                                                                            *
  628. * PARAMETERS:                                                                M
  629. *   ErrorMsg:    Error message to print out.                     M
  630. *                                                                            *
  631. * RETURN VALUE:                                                              M
  632. *   void                                                                     M
  633. *                                                                            M
  634. * KEYWORDS:                                                                  M
  635. *   IritPrsrFatalError                                                       M
  636. *****************************************************************************/
  637. void IritFatalError(char *ErrorMsg)
  638. {
  639.     if (ErrorMsg != NULL) {
  640.     WndwInputWindowPutStr("Fatal error occured, please report it:");
  641.     WndwInputWindowPutStr(ErrorMsg);
  642.     }
  643.  
  644.     FlushToEndOfExpr(TRUE);
  645.  
  646.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  647. }
  648.  
  649. /*****************************************************************************
  650. * DESCRIPTION:                                                               M
  651. * Prints IRIT parser's fatal error message and go back to cursor mode.         M
  652. *                                                                            *
  653. * PARAMETERS:                                                                M
  654. *   ErrorMsg:    Error message to print out.                     M
  655. *                                                                            *
  656. * RETURN VALUE:                                                              M
  657. *   void                                                                     M
  658. *                                                                            M
  659. * KEYWORDS:                                                                  M
  660. *   IritPrsrFatalError                                                       M
  661. *****************************************************************************/
  662. void IritPrsrFatalError(char *ErrorMsg)
  663. {
  664.     if (ErrorMsg != NULL) {
  665.     WndwInputWindowPutStr(ErrorMsg);
  666.     }
  667.  
  668.     FlushToEndOfExpr(TRUE);
  669.  
  670.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  671. }
  672.  
  673. /*****************************************************************************
  674. * DESCRIPTION:                                                               M
  675. * Called from the floating point package in case of fatal floating point     M
  676. * error.                                     M
  677. *   Prints error message and long jumps to main loop.                 M
  678. *   Default FPE handler - must be reset after redirected to other module.    M
  679. *                                                                            *
  680. * PARAMETERS:                                                                M
  681. *   Type:      Of floating point error.                                      M
  682. *                                                                            *
  683. * RETURN VALUE:                                                              M
  684. *   void                                                                     M
  685. *                                                                            *
  686. * KEYWORDS:                                                                  M
  687. *   DefaultFPEHandler                                                        M
  688. *****************************************************************************/
  689. void DefaultFPEHandler(int Type)
  690. {
  691.     char Line[LINE_LEN];
  692.  
  693.     sprintf(Line, "Floating point error %d.", Type);
  694.     WndwInputWindowPutStr(Line);
  695.  
  696.     FlushToEndOfExpr(TRUE);
  697.  
  698.     longjmp(GlblLongJumpBuffer, 1);
  699. }
  700.  
  701. #ifdef DEBUG
  702.  
  703. /*****************************************************************************
  704. * DESCRIPTION:                                                               *
  705. *    Dummy function to link at debugging time.                               *
  706. *                                                                            *
  707. * PARAMETERS:                                                                *
  708. *                                                                            *
  709. * RETURN VALUE:                                                              *
  710. *   void                                                                     *
  711. *                                                                            *
  712. * KEYWORDS:                                                                  *
  713. *****************************************************************************/
  714. void DummyLinkCagdDebug(void)
  715. {
  716.     IritPrsrDbg();
  717. }
  718.  
  719. #endif /* DEBUG */
  720.